<template>
  <div class="watermelon">
    <mynav></mynav>
    <mytabber></mytabber>
    <!-- 顶部固定导航栏 -->
    <van-sticky :offset-top="47" class="nav">
      <van-tabs @click="onClick" sticky>
        <van-tab v-for="item in navList" :key="item.id" :name="item.id" :title="item.title"></van-tab>
      </van-tabs>
    </van-sticky>
    <!-- 点击视频区域 -->
    <div class="melon-box" v-for="el in newsVideo" :key="el.id" @click="getWinfo(el.id)">
      <!-- 视频第一帧图片区域 -->
      <div class="melon-top">
        <img class="wm-img" :src="el.img_url" alt />
        <div class="title">{{el.title}}</div>
        <div class="time">{{el.datetime}}</div>
      </div>
      <!-- 头像区域 -->
      <div class="melon-bottom">
        <img :src="el.img_url" alt />
        <span>{{el.media_name}}</span>
        <span>|</span>
        <span>关注</span>
        <span>
          <van-icon name="chat-o" />
        </span>
        <span>111</span>
        <span>
          <van-icon name="ellipsis" />
        </span>
      </div>
    </div>
    <div class="null"></div>
  </div>
</template>
<script>
import mynav from '@/components/Mynav'
import mytabber from '@/components/Mytabbar'
export default {
  data: () => ({
    id: 2,
    navList: {},
    newsVideo: [],
    searchVideos: []
  }),
  created () {
    this.getNavList()
    this.getNewsvideo(28)
  },
  methods: {
    // 获取顶部导航栏
    async getNavList () {
      const {
        data: { data, status }
      } = await this.$http.get('/api/getnavlist/' + this.id)
      if (status !== 0) return console.log('获取失败')
      this.navList = data
    },
    getWinfo (id) {
      this.$router.push('/winfo/' + id)
    },
    // 获取视频
    async getNewsvideo (id) {
      const {
        data: { data, status }
      } = await this.$http.get('/api/getnewsvideo/' + id)
      if (status !== 0) return console.log('获取失败')
      this.searchVideos = this.newsVideo = data
      // console.log(this.searchVideos)
    },
    onSearchF (value) {
      // console.log(value)
      this.newsVideo = JSON.parse(JSON.stringify(this.searchVideos))
      this.newsVideo = this.newsVideo.filter(item => {
        if (item.title.includes(value)) {
          return true
        }
      })
    },
    onClick (name) {
      this.getNewsvideo(name)
    }
  },
  components: {
    mynav,
    mytabber
  }
}
</script>
<style lang="less" scoped>
.watermelon {
  .nav {
    margin-bottom: 50px;
  }
  .melon-box {
    // margin-top:48px;
    // padding-bottom:40px;
    .melon-top {
      width: 100%;
      height: 200px;
      margin-bottom: 10px;
      position: relative;
      .wm-img {
        width: 100%;
        height: 200px;
      }
      .title {
        position: absolute;
        top: 10px;
        left: 8px;
        color: #fff;
        font-size: 20px;
      }
      .time {
        position: absolute;
        top: 175px;
        right: 6px;
        color: #fff;
        font-size: 12px;
      }
    }
    .melon-bottom {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-right: 10px;
        margin-left: 20px;
      }
      span {
        display: inline-block;
        margin-left: 8px;
        font-size: 14px;
        &:nth-child(4) {
          color: red;
        }
        &:nth-child(5) {
          margin-left: 80px;
        }
      }
    }
  }
  .null {
    height: 42px;
  }
}
</style>
